//
// Created by weslywang on 2020/5/30.
//

#ifndef LEETCODE2020_BITSET_H
#define LEETCODE2020_BITSET_H

#include <vector>

using namespace std;

class BitSet {
public:
    BitSet(size_t range) {
        //当range为8以下的时候，会开辟0个空间，会出错
        _bitSet.resize(range / 8 + 1, 0);
    }

    void Set(size_t value) {
        size_t index = value / 8;  //value>>3
        size_t pos = value % 8;

        _bitSet[index] |= (1 << pos); //置1：或1
    }

    void ReSet(size_t value) //重置
    {
        size_t index = value / 8;
        size_t pos = value % 8;

        _bitSet[index] &= ~(1 << pos); //置0: 与0
    }

    bool Test(size_t value) //检测
    {
        size_t index = value / 8;
        size_t pos = value % 8;

        return _bitSet[index] & (1 << pos);

    }

protected:
    vector<char> _bitSet;
};

#endif //LEETCODE2020_BITSET_H
